package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.salary.service.IAgencySalaryHistoryService;
import com.boss.sys.ca.user.dto.UserDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/agencySalaryHistoryController")
public class AgencySalaryHistoryController extends BasicinfoBaseController {
    
    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(AgencySalaryHistoryController.class);

    @Autowired
    private IAgencySalaryHistoryService agencySalaryHistoryService;

    /**
     * 十三月工资：通过机构ID和工资月份查询工资字段
     * @param agencyId
     * @param month
     * @return
     */
    @GetMapping("/queryColumnByAgencyIdAndSalaryMonth")
    public ApiResultDTO queryColumnByAgencyIdAndSalaryMonth(@RequestHeader("tokenid") String tokenid,
                                                        @RequestParam("agencyId") String agencyId, @RequestParam("month") String month){
        try{
            UserDTO userDTO = getUser(tokenid);
            List<Map<String, Object>> result = agencySalaryHistoryService.getColumnByAgencyIdAndSalaryMonth(userDTO.getProvince(), agencyId, month);
            return ApiResultDTO.success(result);
        }catch(Exception e){
            logger.warn(e.getMessage());
            return ApiResultDTO.error(ERROR_RSCODE, "查询数据异常");
        }
    }


}
